﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AStartTest
{
    public class AStart
    {
        public static List<MapPos> AA(Map2D _map, MapPos start, MapPos end)
        {
            List<MapPos> openList = new List<MapPos>();
            List<MapPos> closeList = new List<MapPos>();


            openList.Add(start);

            while (!IsInOpenList(end, openList) || openList.Count == 0)
            {
                MapPos minPos = GetMinCostPos(openList, end);

                if (minPos == null)
                {
                    return openList;
                }
            }

            return null;
        }


        private static bool IsInOpenList(MapPos pos, List<MapPos> openList)
        {
            return true;
        }

        private static MapPos GetMinCostPos(List<MapPos> openList, MapPos endPos)
        {
            MapPos minPos = null;
            foreach (MapPos item in openList)
            {
                if (minPos == null || GetG(minPos) + GetH(minPos, endPos) > GetG(item) + GetH(item, endPos))
                {
                    minPos = item;
                }
            }
            return minPos;
        }

        private static int GetG(MapPos pos)
        {
            return 0;
        }

        private static int GetH(MapPos pos, MapPos endPos)
        {
            return Math.Abs(pos.Row - endPos.Row) + Math.Abs(pos.Col - endPos.Col);
        }

    }
}
